package com.jtx.miaoah2.Controller;

import com.jtx.miaoah2.Common.BaseResponse;
import com.jtx.miaoah2.Model.goods.DO.SkGoods;
import com.jtx.miaoah2.Service.SkGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 季台星
 * @Date 2023 07 23 15 50
 */
@RestController
@RequestMapping("/api/v1")
public class SkGoodsController {
    @Autowired
    private SkGoodsService skGoodsService;
    @GetMapping("/goods")
    public BaseResponse getGoodsList(@RequestParam("pageSize") Integer pageSize,
                                     @RequestParam("pageNo") Integer pageNo){
        return skGoodsService.getGoodsPage(pageNo,pageSize);
    }

    @GetMapping("/goods/{id}")
    public BaseResponse getGoodsList(@PathVariable("id") Long id){
        return BaseResponse.success(skGoodsService.getGoodsById(id));
    }

    @DeleteMapping("/goods/{id}")
    public BaseResponse delete(@PathVariable("id") Long id){
        return BaseResponse.success(skGoodsService.removeById(id));
    }
    @PutMapping("/goods")
    public BaseResponse updateGoods(@RequestBody SkGoods skGoods){
        return BaseResponse.success(skGoodsService.updateById(skGoods));
    }
}
